window.onload = initPage();
function initPage(){
	//
}
function login(){
	document.getElementById("loginaction").setAttribute("value", "Dang xu ly...");
	username = document.getElementById("username");
	password = document.getElementById("password");
	request = createRequest();
	if(request === null){
		alert("Khong the khoi tao XMLHttpRequest!");
	}
	var params = "username=" +username.value+ "&password=" +password.value;
	request.onreadystatechange = checkLogin;
	request.open("POST", "/login", true);
	request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	request.setRequestHeader("Content-length", params.length);
	request.setRequestHeader("Connection", "close");
	request.send(params);
}

function checkLogin(){
	if(request.readyState === 4){
		if(request.status === 200){
			if(request.responseText == "fail"){
				alert("Ten dang nhap hoac mat khau khong dung!");
				username.value = "";
				password.value = "";
				username.focus();
				document.getElementById("loginaction").setAttribute("value", "Dang nhap");
			}else if(request.responseText == "ok"){
				window.location.href = "/chat";
			}
		}
	}
}